package com.mswork.mes.service.impl;


import com.mswork.common.core.domain.model.LoginUser;
import com.mswork.common.utils.SecurityUtils;
import com.mswork.mes.domain.User;
import com.mswork.mes.mapper.UserMapper;
import com.mswork.mes.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> getDriverList(){
        return userMapper.getDriverList();
    }
    @Override
    public List<User> getUserList(){
        return userMapper.getUserList();
    }

    @Override
    public String getRole() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long userId = loginUser.getUserId();
        User userInfo = userMapper.getUserInfo(userId);
        if(userInfo.getRoleKeys() != null ){
            if(userInfo.getRoleKeys().contains("admin") || userInfo.getRoleKeys().contains("superAdmin")){
                return "admin";
            }else if(userInfo.getRoleKeys().contains("manager")){
                //管理角色
                return "manager";
            }
        }
        if(userInfo.getPostCodes() != null ){
            if(userInfo.getPostCodes().contains("driver")){
                //司机
                return "driver";
            }else if(userInfo.getPostCodes().contains("kg")){
                //库管
                return "kg";
            }
        }
        return null;
    }

}
